/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package entities.users;

import entities.tools.Form;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author Marek
 */
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name="companyowner")
@DiscriminatorValue("CompanyOwner")
public class CompanyOwner extends AbstractUser implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 
     */     
    @OneToMany(cascade=(CascadeType.PERSIST),fetch = FetchType.LAZY, mappedBy = "companyOwner")
    private List<Form> forms = new ArrayList<>();

    /**
     * 
     */
    @ManyToMany(cascade=(CascadeType.PERSIST))
    @JoinTable(
            name = "company_form_signer",
            joinColumns = {
                @JoinColumn(name = "company_id", referencedColumnName = "id")},
            inverseJoinColumns = {
                @JoinColumn(name = "form_signer_id", referencedColumnName = "id")})
    private List<FormSigner> formSigners = new ArrayList<>();

    /**
     * 
     */
    @OneToMany(cascade=(CascadeType.PERSIST),fetch = FetchType.LAZY, mappedBy = "companyOwner")
    private List<FormOwner> formOwners = new ArrayList<>();

    /**
     * 
     * @return id 
     */
    @Override
    public Long getId() {
        return id;
    }

    /**
     * 
     * @param id 
     */
    @Override
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * 
     * @return 
     */
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    /**
     * 
     * @param object
     * @return 
     */
    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof CompanyOwner)) {
            return false;
        }
        CompanyOwner other = (CompanyOwner) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    /**
     * 
     * @return text representation of the CompanyOwner object 
     */
    @Override
    public String toString() {
        return "entities.users.CompanyOwner[ id=" + id + " ]";
    }

    /**
     * @return the formSigners
     */
    public List<FormSigner> getFormSigners() {
        return formSigners;
    }

    /**
     * @param formSigners the formSigners to set
     */
    public void setFormSigners(List<FormSigner> formSigners) {
        this.formSigners = formSigners;
    }

    /**
     * @return the agents
     */
    public List<FormOwner> getFormOwners() {
        return this.formOwners;
    }

    /**
     * @param formOwners the agents to set
     */
    public void setFormOwners(List<FormOwner> formOwners) {
        this.formOwners = formOwners;
    }

    /**
     * @return the forms
     */
    public List<Form> getForms() {
        return forms;
    }

    /**
     * @param forms the forms to set
     */
    public void setForms(List<Form> forms) {
        this.forms = forms;
    }

}
